﻿#pragma once
#include <qwidget>
#include <qtablewidget>
#include <qpushbutton>
#include <qcombobox>
#include <qcheckbox>
#include "opencv2/opencv.hpp"

class QGView;
class VisionMainWnd;
class DebugWin :
    public QWidget
{
    Q_OBJECT
public:
    explicit DebugWin(QWidget* parent = nullptr);

    void init();
    void stopProcess() { stopBatchPro_ = true; };

    // 采集一帧：离线接口，相当于单步调试
    void grabOnce();
    bool getImageBuffer(cv::Mat& src);

protected:
    void createTable();
    void clearTable();
    // 批处理：用于连续处理模拟
    void batchProcess();

private slots:
    void openFiles();
    void delTable();

    // 单步调试
    void stepDebug();
    // 连续处理
    void continueDebug();
    // 停止处理
    void stopDebug();
    // 循环处理:checkbox选中、取消响应
    void onCheckBoxStateChanged(int);

    void updateTable(int signal, double t);

    void on_itemSelected(int index);

signals:
    void sendImage(QImage);
    void sendToTable(int, double);

private:
    QTableWidget* tableImageFiles_ = nullptr;
    bool stopBatchPro_ = false;
    bool loopPro_ = false;

    // 操作按钮
    QPushButton* addFile_ = nullptr;
    QPushButton* clearFiles_ = nullptr;
    QPushButton* stepDebug_ = nullptr;
    QPushButton* continueDebug_ = nullptr;

    QComboBox* selCam_ = nullptr;
    int selCamIndex_ = 0;
    
    QCheckBox* loopCheck_ = nullptr;
    QPushButton* stopPro_ = nullptr;

    QString filesDir_ = "";

    VisionMainWnd *mainWin_ = nullptr;
};

